import Vue from 'vue';
import confirm from './confirm1.vue';

const confirmConstructor = Vue.extend(confirm);
const confirmDom = new confirmConstructor({
  el: document.createElement('div'),
});
document.body.appendChild(confirmDom.$el);
confirm.install = (vm) => {
  vm.prototype.$customConfirm1 = (obj) => {
    confirmDom.$props.content = obj.content || "删除会清空数据且不可撤销 确认删除？";
    confirmDom.$props.icon = obj.icon || "el-icon-warning"
    confirmDom.$props.title = obj.title || '信息提示';
    confirmDom.$props.cancelTxt = obj.cancelTxt || '取 消';
    confirmDom.$props.confirm = obj.confirm || '确 定';
    confirmDom.open();
    confirmDom.$on('confirm', () => {
      if (obj.onok && typeof obj.onok == "function") {
        obj.onok();
      }
      confirmDom.$off('confirm');
      confirmDom.$off('cancel');
    });

    confirmDom.$on('cancel', () => {
      if (obj.oncancel && typeof obj.oncancel == "function") {
        obj.oncancel();
      }
      confirmDom.$off('cancel');
      confirmDom.$off('confirm');
    });
  };
};

export default confirm;